#include <amxmodx>
#include <fakemeta>
#include <colorchat>

new bool:g_mute[33][33]
new g_menuchoose[33][33]

public plugin_init()
{
    register_plugin("Voice Manager", "1.0", "ReymonARG/Cheap_Suit")
    register_clcmd("say /mute", "chat")
    register_clcmd("say_team /mute", "chat")
    
    register_forward(FM_Voice_SetClientListening, "fwd_voice_setclientlistening")
    set_task(45.0, "showInfo")
    
}
public showInfo(){
	
	ColorChat(0,  RED, "^4Wnerwia Cie czyjs glos? Wpisz ^3/mute^4 i wycisz go!");
	set_task(95.0, "showInfo");
}

public client_connect(id)
{
    for(new i = 0; i <= 32; ++i) 
        g_mute[id][i] = false
}

public fwd_voice_setclientlistening(receiver, sender, listen) 
{
    if(receiver == sender)
        return FMRES_IGNORED
    
    if(g_mute[receiver][sender])
    {
        engfunc(EngFunc_SetClientListening, receiver, sender, 0)
        return FMRES_SUPERCEDE
    }
    return FMRES_IGNORED
}

public chat(id)
{
    openmenu(id, 0)
    return PLUGIN_HANDLED
}

stock openmenu(id, page)
{        
    new menu = menu_create("\rMute Menu", "menuaccion")
    new textmenu[64], count = 1
    
    for(new i = 1; i <= 32 ; i++)
    {
        if( !is_user_connected(i) || is_user_bot(i) || is_user_hltv(i) )
            continue;
        
        new name[32], num[2]
        get_user_name(i, name, 31)
        num_to_str(count, num, 1)
        g_menuchoose[id][count++] = i
        formatex(textmenu, 63, "%s%s %s", id == i ? "\d" : "\w", name, g_mute[id][i] ? "\y(Muted)" : "")
        menu_additem(menu, textmenu, num, 0)
    }
    
    menu_display(id, menu, page)
    
    return PLUGIN_HANDLED;
}

public menuaccion(id, menu, item)
{
    if(item == MENU_EXIT)
    {
        return PLUGIN_HANDLED
    }
    
    new data[2], iName[64]
    new access, callback
    
    menu_item_getinfo(menu, item, access, data, 1, iName, 63, callback)
    
    new i = g_menuchoose[id][str_to_num(data)]
    
    if( i != id )
        g_mute[id][i] = !g_mute[id][i]
    
    openmenu(id, 0)
    return PLUGIN_HANDLED
}  
